
	
	var app = angular.module("main",['ngRoute'])
	
	app.config(['$routeProvider',function($routerProvider){
		$routerProvider.when('/home_page',{
			templateUrl:'./index/index.html',
			controller:'indexCtrl'
		})
		.when('/details/:id',{
			templateUrl:'./details/details.html',
			controller:'detailsCtrl'
		})
		.when('/:in_theaters/:id?',{
			templateUrl:'./in_theaters/in_theaters.html',
			controller:'intheatersCtrl'
		})
		
	}])
	
   
   app.service('ajaxjsonp',['$window',function($window){
	   	this.jsonp = function(defaults){
		   	 var cbName = 'jQuery' + ('1.11.1' + Math.random()).replace(/\D/g,"") + '_' + (new Date().getTime());
		    if(defaults.jsonpCallback){
		        cbName = defaults.jsonpCallback;
		    }
		
		    // 这里就是回调函数，调用方式：服务器响应内容来调用
		    // 向window对象中添加了一个方法，方法名称是变量cbName的值
		    window[cbName] = function(data){
		        defaults.success(data);//这里success的data是实参
		    }
		
		    var param = '';
		    for(var attr in defaults.data){
		        param += attr + '=' + defaults.data[attr] + '&';
		    }
		    if(param){
		        param = param.substring(0,param.length-1);
		        param = '&' + param;
		    }
		    var script = document.createElement('script');
		    script.src = defaults.url + '?' + defaults.jsonp + '=' + cbName + param;
		    var head = document.getElementsByTagName('head')[0];
		    head.appendChild(script);
	   	}
   }])
   
   app.controller("activeCtrl",["$scope","$location",function($scope,$location){
   			
   	    $scope.loca = $location
        // 监视锚点值变化
        $scope.$watch('loca.url()', function(now, old){	
        	$scope.activestatus = now.match(/\/(\w+)(\/*)/)[1] 
        	$scope.activestatus = "/" + $scope.activestatus;
        })
   			
   	 
   	
   }])
